<?php
require_once 'util/ConfigUtil.php';
require_once 'util/ServiceUtil.php';
require_once 'util/StringUtil.php';
class BaseService 
{	
	protected $myDb;//mysql_connect
	protected $sql;//string
	protected $query;//string
	protected $numRows;//int
	protected $result;//array
	
	public function BaseService() 
	{
		$this->myDb = null;
		$this->sql = null;
		$this->query = null;
		$this->numRows = 0;
		$this->result = array();
		$this->initializeDB();
	}
	
	protected function initializeDB()
	{
		try {
			$this->myDb = mysql_connect(ConfigUtil::SERVER_NAME(),ConfigUtil::MYSQL_USERNAME(),ConfigUtil::MYSQL_PASSWORD());
			mysql_select_db(ConfigUtil::MYSQL_TABLENAME(),$this->myDb);
			mysql_query("SET NAMES 'utf8'");
			echo "InitializeDB success!";
		}catch (Exception $exc)
		{
			trigger_error("InitializeDB error!".$exc);
		}
	}
	
	protected  function checkQueryResult($affectedNumRows,$location)
	{
		if($affectedNumRows==1)
		{
			if(is_null($location))
			{
				return ServiceUtil::getSuccessResult(ServiceUtil::SUCCESS,(__CLASS__).("::").(__FUNCTION__));
			}else
			{
				return ServiceUtil::getSuccessResult(ServiceUtil::SUCCESS,$location);
			}
			
		}else
		{
			if(is_null($location))
			{
				return ServiceUtil::getFailureResult(ServiceUtil::FAILURE,(__CLASS__).("::").(__FUNCTION__));
			}else
			{
				return ServiceUtil::getFailureResult(ServiceUtil::FAILURE,$location);
			}
		}
	}
	
}

?>